<?php
//注册模块
class AgentAction extends CommonAction{
	
	public function _initialize() {
		header("Content-Type:text/html; charset=utf-8");
		$this->_inject_check(0);//调用过滤函数
		$this->_Config_name();//调用参数
 		$this->_checkUser();
	}
	
	
	public function cody(){
		//===================================二级验证
		$UrlID = (int) $_GET['c_id'];
		if (empty($UrlID)){
			$this->error('二级密码错误!');
			exit;
		}
		if(!empty($_SESSION['user_pwd2'])){
			$url = __URL__."/codys/Urlsz/$UrlID";
			$this->_boxx($url);
			exit;
		}
		$cody   =  M ('cody');
		$list	=  $cody->where("c_id=$UrlID")->field('c_id')->find();
		if ($list){
			$this->assign('vo',$list);
			$this->display('Public:cody');
			exit;
		}else{
			$this->error('二级密码错误!');
			exit;
		}
	}
	public function codys(){
		//=============================二级验证后调转页面
		$Urlsz = (int) $_POST['Urlsz'];
		if(empty($_SESSION['user_pwd2'])){
			$pass  = $_POST['oldpassword'];
			$fck   =  M ('fck');
			if (!$fck->autoCheckToken($_POST)){
				$this->error('页面过期请刷新页面!');
				exit();
			}
			if (empty($pass)){
				$this->error('二级密码错误!');
				exit();
			}
	
			$where = array();
			$where['id'] = $_SESSION[C('USER_AUTH_KEY')];
			$where['passopen'] = md5($pass);
			$list = $fck->where($where)->field('id,is_agent')->find();
			if($list == false){
				$this->error('二级密码错误!');
				exit();
			}
			$_SESSION['user_pwd2'] = 1;
		}else{
			$Urlsz = $_GET['Urlsz'];
		}
		switch ($Urlsz){
			case 1;
				if($list['is_agent'] >=2){
					$this->error('您已经是报单中心!');
            		exit();
				}
				$_SESSION['Urlszpass'] = 'MyssXiGua';
				$bUrl = __URL__.'/agents';//申请代理
                $this->_boxx($bUrl);
			break;
				case 2;
				$_SESSION['Urlszpass'] = 'MyssShuiPuTao';
				$bUrl = __URL__.'/menber'; //未开通会员
				$this->_boxx($bUrl);
			break;
		
			case 3;
				$_SESSION['Urlszpass'] = 'Myssmenberok';
				$bUrl = __URL__.'/menberok'; //已开通会员
				$this->_boxx($bUrl);
			break;
			
			case 4;
				$_SESSION['UrlPTPass'] = 'MyssGuanXiGua';
				$bUrl = __URL__.'/adminAgents'; //后台确认报单中心
				$this->_boxx($bUrl);
			break;
			default;
                $bUrl = __APP__;
                $this->_box(1,'二级密码已验证，无需重复操作！',$bUrl,1);
			exit;
		}
	}

	public function agentCenter(){
        $id = $_SESSION[C('USER_AUTH_KEY')];
	    $fck_rs = M('fck')->field('is_agent')->find($id);
        $this->assign('fck_rs',$fck_rs);
	    $this->display();
    }


	public function agents($Urlsz=0){
		//======================================申请会员中心/报单中心/报单中心
		if ($_SESSION['Urlszpass'] == 'MyssXiGua'){
			$fee_rs = M ('fee') -> find();
	
			$fck = M ('fck');
			$where = array();
			//查询条件
			$where['id'] = $_SESSION[C('USER_AUTH_KEY')];
			$field ='*';
			$fck_rs = $fck ->where($where)->field($field)->find();
	
			if ($fck_rs){
				//会员级别
				switch($fck_rs['is_agent']){
					case 0:
						$agent_status = '未申请报单中心!';
						break;
					case 1:
						$agent_status = '申请正在审核中!';
						break;
					case 2:
						$agent_status = '报单中心已开通!';
						break;
				}
	
				$this->assign ( 'fee_s6',$fee_rs['i1']);
				$this->assign ( 'agent_level',0);
				$this->assign ( 'agent_status',$agent_status);
				$this->assign ( 'fck_rs', $fck_rs);
				
				$Agent_Us_Name = C('Agent_Us_Name');
				$Aname = explode("|",$Agent_Us_Name);
				$this->assign ( 'Aname', $Aname);
				
				$this->display ('agents');
			}else{
				$this->error ('操作失败!');
				exit;
			}
		}else{
			$this->error ('错误!');
			exit;
		}
	}
	
	
	public function agentsAC(){
		//================================申请会员中心中转函数
		$content  = $_POST['content'];
		$agentMax = $_POST['agentMax'];
		$shoplx  = (int)$_POST['shoplx'];
		$shop_a  = $_POST['shop_a'];
		$shop_b  = $_POST['shop_b'];
		$fee=M('fee');
		$fee_rs=$fee->where('s9,s14')->find(1);
		$s14=(int)$fee_rs['s14'];
    	$s9 = explode("|",$fee_rs['s9']);		//会员级别费用
//		$one_mm = $s9[0];
		$one_mm = 1;
		
/*		if($shoplx==1){
			if($shop_a == "请选择"){
				$this->error('请输入报单中心区域!');
			}
		}else{
			if($shop_a == "请选择" || $shop_b == "请选择"){
				$this->error('请输入报单中心区域!');
			}
		}*/
		
		$fck = M ('fck');
		$id = $_SESSION[C('USER_AUTH_KEY')];		
		$where = array();
		$where['id'] = $id;
	
		$fck_rs = $fck->where($where)->field('*')->find();
		if($fck_rs){
			if($fck_rs['is_pay']  == 0){
				$this->error ('临时会员不能申请!');
				exit;
			}
			if($fck_rs['is_agent']  == 1){
				$this->error('上次申请还没通过审核!');
				exit;
			}
			if($fck_rs['u_level']  < 1){
				$this->error('只有5星可以申请报单中心!');
				exit;
			}
			
//			$bqycount=0;
//			if($shoplx==1){
//				$bqycount = $fck->where("is_agent>0 and shop_a=".$shop_a)->count;
//			}elseif($shoplx==2){
//				$bqycount = $fck->where("is_agent>0 and shop_b=".$shop_b)->count;
//			}
//			if($bqycount>0){
//				$this->error('本区域的报单中心已经存在!');
//				exit;
//			}

			if(empty($content)){
 				$this->error ('请输入备注!');
 				exit;
			}

	
			if($fck_rs['is_agent'] == 0){
				$nowdate = time();
				$result = $fck -> query("update __TABLE__ set verify='".$content."',is_agent=1,shoplx=".$shoplx.",shop_a='".$shop_a."',shop_b='".$shop_b."',idt=$nowdate where id=".$id);
			}
	
			$bUrl = __URL__ .'/agents';
			$this->_box(1,'申请成功！',$bUrl,2);
	
		}else{
			$this->error('非法操作');
			exit;
		}
	}
	
	//未开通会员
	public function menber($Urlsz=0){
		//列表过滤器，生成查询Map对象
		if ($_SESSION['Urlszpass'] == 'MyssShuiPuTao'){
			$fck = M('fck');
			$map = array();
			$id = $_SESSION[C('USER_AUTH_KEY')];
			$gid = (int) $_GET['bj_id'];
// 			$map['shop_id'] = $id;
			$UserID = $_POST['UserID'];
			if (!empty($UserID)){
				import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
				$where['nickname'] = array('like',"%".$UserID."%");
				$where['user_id'] = array('like',"%".$UserID."%");
				$where['_logic']    = 'or';
				$map['_complex']    = $where;
				$UserID = urlencode($UserID);
			}
			$map['is_pay'] = array('eq',0);
			$map['_string'] = "shop_id=".$id." or re_path like',%".$id."%,'";

            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
    	    $listrows = 10;//每页显示的记录数
            $page_where = 'UserID='.$UserID;//分页条件
            $Page = new ZQPage($count, $listrows,1, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('is_pay asc,pdt desc')->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            //=================================================
            
			$HYJJ = '';
            $this->_levelConfirm($HYJJ,1);
            $this->assign('voo',$HYJJ);//会员级别
			$where = array();
			$where['id'] = $id;
			$fck_rs = $fck->where($where)->field('*')->find();
			$this->assign('frs',$fck_rs);//注册币
			
			
			$new_userid = $this->_getUserID();
			$fee = M('fee');
			$fee_s = $fee->field('*')->find();
			$s9 = explode('|',$fee_s['s9']);//投资额
			$s2 = explode('|',$fee_s['s2']);//投资单数
            //先看系统是否允许使用积分开通：字段str20
            $str20=(int)$fee_s['str20'];
            $this->assign('str20',$str20);
			$this->assign('s9',$s9);
			$this->assign('s2',$s2);
			$this->assign('Money',$fee_s['s2']);
			$this->assign('new_userid',$new_userid);



			
			//查找子账号的信息
            $field  = '*';
           //=====================分页开始==============================================
			import ( "@.ORG.ZQPage1" );  //导入分页类
			$count = $fck->where('x_num>0 and x_num='.$id)->count();//总页数
			$listrows = 10;//每页显示的记录数
			$Page = new ZQPage1($count,$listrows,1);
			//===============(总页数,每页显示记录数,css样式 0-9)
			$show = $Page->show();//分页变量
            $this->assign('page1',$show);//分页变量输出到模板
            $wrs = $fck->where('x_num>0 and x_num='.$id)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();
            $this->assign('wrs',$wrs);//数据输出到模板
            //=================================================
			$this->display ();
			exit;
		}else{
			$this->error('数据错误!');
			exit;
		}
	}
	public function laqu($Urlsz=0){
        $fck = D('Fck');
        $fee = M('fee');

		$id = $_SESSION[C('USER_AUTH_KEY')];
		$user=$fck->where('id='.$id)->find();
		if(!$user){
			exit;
		}
		$user_id=$user['user_id'];
		//查找子账号的信息
		$field  = '*';
		$xiaohao = $fck->where('x_num>0 and x_num='.$id)->select();//总页数

        //先检查所有子账号的二级密码与主的一样吗？有一个不一样直接退出
        foreach ($xiaohao as $item) {
//            echo $item['user_id'].$user['passopen'].'==='.$item['passopen'].'<br>';
            if($item['passopen']!=$user['passopen']){
                echo 'passopen';
                exit;
            }
        }


        //开始统计拉取的钱了
        $fee_rs=$fee->field('str17')->find();
        $limit_day=(int)$fee_rs['str17'];

        $member_count=0;
		$money_count=0;
		foreach ($xiaohao as $item) {
			if($item['fanli_money']>=$limit_day){
				$member_count+=1;
				$money_count+=$item['agent_use'];
				$fck->execute('update __TABLE__ set agent_use=0 where id='.$item['id']);
			}
		}
		$fck->execute('update __TABLE__ set agent_use=agent_use+'.$money_count.' where id='.$id);
		if($money_count>0){
			$fck->addencAdd($id,$user_id,$money_count);
		}
        echo "达到{$limit_day}个分红日的子账号个数为：{$member_count},共计{$money_count}元！";
	}

	//生成会员编号
	private function _getUserID(){
		$fck = M('fck');
		
		$mynn = ''.rand(1000000,9999999);
		
		$fwhere['user_id'] = $mynn;
		$frss = $fck->where($fwhere)->field('id')->find();
		if ($frss){
			return $this->_getUserID();
		}else{
			unset($fck,$fee);
			return $mynn;
		}
	}
	//找出最后一个子账号
	public function last_x_num111($id){
		$fck=M('fck');
		$count=$fck->where('x_num='.$id)->count();
		if($count){
			return $fck->where('x_num='.$id)->field('id,user_id,re_path,re_name,re_id,re_level,get_ceng')->order('get_ceng desc')->find();
		}else{
			return $fck->where('id='.$id)->field('id,user_id,re_path,re_name,re_id,re_level,get_ceng')->find();
		}
	}
	//开通子帐号
	public function OpenFormyself111(){
		//echo"---33333-----";
		//exit;
		$fck = D ('Fck');
		$fee = M ('fee');
		$gouwu = M ('gouwu');
		$shouru = M ('shouru');
		
		if (!$fck->autoCheckToken($_POST)){
			$this->error('页面过期请刷新页面！');
			exit;
		}
		$uLevel = $_POST['u_level'];

		$fee = M('fee');
		$fee_rs = $fee->field('s12,s9,i5')->find();

		$s12 = $fee_rs['s12'];//互助奖
		$s9 =$fee_rs['s9'];
		$nowdate = strtotime(date('c'));
		$nowday=strtotime(date('Y-m-d'));
		//会员级别
		$count=(int)htmlspecialchars($_POST['count']);
		if($count<1){
			$this->error('单数出错！');
		}
		$ulevel2 = $s9*$count;//每单多少钱*多少单
		$new_userid = $_POST['UserID'];

		$ID = $_SESSION[C('USER_AUTH_KEY')];
		$us_mm = $s12;
		
		//系统关闭开通子账号的开关
		if($fee_rs['i5']==0){
			$this->error('系统暂时不允许开通子账号,请联系管理员!');
			exit;
		}

		//被開通玩家參數
		$where = array();
		$where['id'] = $ID;
		$where['is_pay'] = array('gt',0);
		$field = '*';
		$myrs = $fck ->where($where)->field($field)->find();
		if(!$myrs){
			$this->error('账户不存在或未开通！');
			exit;
		}
		$us_money = $myrs['agent_use'];//积分
		$money_a = 0;
			
		if ($us_money <= $money_a){
			$this->error('账户余额不足！');
			exit;
		}
		$result = $fck->execute("update __TABLE__ set `agent_use`=agent_use-".$ulevel2." where `id`=".$ID);//开通子账号的时候扣除信用积分

		if($result){
			for($i=0;$i<$count;$i++) {
				$kt_cont = "开通子帐户";
				$data = array();

				//推荐人 start
				$re_info=$this->last_x_num($ID);
				$data['re_path'] = $re_info['re_path'].$re_info['id'].',';  //推薦路徑
				$data['re_id'] = $re_info['id'];                              //推薦人ID
				$data['re_name'] = $re_info['user_id'];                       //推薦人帳號
				$data['re_level'] = $re_info['re_level'] + 1;                 //代數(絕對層數)
				$data['get_ceng'] = $re_info['get_ceng'] + 1;                 //代數(絕對層數)
					//主帐号不加推荐人数，子帐号能加
				if($re_info['id']!=$ID){
					$fck->execute('update __TABLE__ set re_nums=re_nums+1 where id='.$re_info['id']);
				}
				//推荐人 end

				$varray = $this->gongpaixtsmall($data['re_id']);

				$data['father_id'] = $varray['father_id'];
				$data['father_name'] = $varray['father_name'];
				$data['treeplace'] = $varray['treeplace'];
				$data['p_level'] = $varray['p_level'];
				$data['p_path'] = $varray['p_path'];
				$data['u_pai'] = $varray['u_pai'];

				$data['user_id'] = $myrs['user_id'].(string)($re_info['get_ceng'] + 1);
				$data['bind_account'] = '3333';
				$data['last_login_ip'] = '';                            //最後登錄IP
				$data['verify'] = '0';
				$data['status'] = 1;                             //狀態(?)
				$data['type_id'] = '0';
				$data['last_login_time'] = time();                        //最後登錄時間
				$data['login_count'] = 0;                             //登錄次數
				$data['info'] = '信息';
				$data['name'] = '名稱';
				$data['password'] = $myrs['password'];
				$data['passopen'] = $myrs['passopen'];
				$data['pwd1'] = $myrs['pwd1'];
				$data['pwd2'] = $myrs['pwd2'];

				$data['wenti'] = $myrs['wenti'];
				$data['wenti_dan'] = $myrs['wenti_dan'];

				$data['bank_name'] = $myrs['bank_name'];
				$data['bank_card'] = $myrs['bank_card'];
				$data['user_name'] = $myrs['user_name'];
				$data['nickname'] = $myrs['nickname'];
				$data['bank_province'] = $myrs['bank_province'];
				$data['bank_city'] = $myrs['bank_city'];
				$data['bank_address'] = $myrs['bank_address'];
				//$data['user_post']           = $myrs['user_post'];		   //
				$data['user_code'] = $myrs['user_code'];
				$data['user_address'] = $myrs['user_address'];
				$data['email'] = $myrs['email'];
				$data['qq'] = $myrs['qq'];
				$data['user_tel'] = $myrs['user_tel'];
				$data['rdt'] = time();
				$data['u_level'] = $uLevel + 1;
				$data['y_level'] = $myrs['y_level'];
				$data['cpzj'] = $s9;
				$data['f4'] = 1;
				$data['wlf'] = 0;

				$data['is_pay'] = 1;
				$data['rdt'] = time();
				$data['pdt'] = time();
				$data['open'] = 0;
				$data['get_date'] = $nowday;
				$data['fanli_time'] = $nowday;

				$data['x_num'] = $myrs['id'];

				//  开通以后就是小公排
				$data['father_id'] = $myrs['father_id'];
				$data['father_name'] = $myrs['father_name'];
				$data['treeplace'] = $myrs['treeplace'];
				$data['p_level'] = $myrs['p_level'];
				$data['p_path'] = $myrs['p_path'];
				$data['u_pai'] = $myrs['u_pai'];

				$resss = $fck->add($data);
				echo $fck->getDbError();
				unset($data);

				$fck->addencAdd($myrs['id'], $myrs['user_id'], -$ulevel2, 26, 0, 0, 0, $kt_cont);//歷史記錄

				//給推薦人添加推薦人數或單數
				//$fck->query("update __TABLE__ set `re_nums`=re_nums+1,re_f4=re_f4+".$myrs['f4']." where `id`=".$myrs['id']);

				$data = array();
				$data['uid'] = $resss;
				$data['user_id'] = $myrs['user_id'].(string)($re_info['get_ceng'] + 1);
				$data['in_money'] = $ulevel2;
				$data['in_time'] = time();
				$data['in_bz'] = "开通子账号";
				$shouru->add($data);
				unset($data);

				$danshu = $ulevel2 / 100;

				//統計單數
				// $fck->xiangJiao($resss, $danshu);//传新人的id  新人的单数

				// //算出獎金
				// $fck->getusjj($resss, 1, $ulevel2);//传新人的id   1   新人的投资额
			}
		}




		unset($fck,$where);
		if ($result){
			unset($vo);
			$bUrl = __URL__.'/menber';
			$this->_box(1,'开通子账号成功！',$bUrl,10);
			exit;
		}else{
			$this->error('开通子账号失败！');
			exit;
		}
	}
	//未开通会员
	public function menberok($Urlsz=0){
		//列表过滤器，生成查询Map对象
		if ($_SESSION['Urlszpass'] == 'Myssmenberok'){
			$fck = M('fck');
			$map = array();
			$id = $_SESSION[C('USER_AUTH_KEY')];
			$gid = (int) $_GET['bj_id'];
			$map['shop_id'] = $id;
			$map['is_pay'] = array('gt',0);
			$UserID = $_POST['UserID'];
			if (!empty($UserID)){
				import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
				$where['nickname'] = array('like',"%".$UserID."%");
				$where['user_id'] = array('like',"%".$UserID."%");
				$where['_logic']    = 'or';
				$map['_complex']    = $where;
				$UserID = urlencode($UserID);
			}

            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
    	    $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = 'UserID='.$UserID;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('is_pay asc,pdt desc')->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            //=================================================


			//查找子账号的信息
			$field  = '*';
			//=====================分页开始==============================================
			import ( "@.ORG.ZQPage1" );  //导入分页类
			$count = $fck->where('x_num>0 and x_num='.$id)->count();//总页数
			$listrows = 10;//每页显示的记录数
			$Page = new ZQPage1($count,$listrows,1);
			//===============(总页数,每页显示记录数,css样式 0-9)
			$show = $Page->show();//分页变量
			$this->assign('page1',$show);//分页变量输出到模板
			$wrs = $fck->where('x_num>0 and x_num='.$id)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();
			$this->assign('wrs',$wrs);//数据输出到模板
			//=================================================

            
			$HYJJ = '';
            $this->_levelConfirm($HYJJ,1);
            $this->assign('voo',$HYJJ);//会员级别
			$where = array();
			$where['id'] = $id;
			$fck_rs = $fck->where($where)->field('*')->find();
			$this->assign('frs',$fck_rs);//注册币
			$this->display ('menberok');
			exit;
		}else{
			$this->error('数据错误!');
			exit;
		}
	}
	
	
	public function menberAC(){
		//处理提交按钮
		$action = $_POST['action'];
		//获取复选框的值
		$OpID = $_POST['tabledb'];
		if (!isset($OpID) || empty($OpID)){
			$bUrl = __URL__.'/menber';
			$this->_box(0,'没有该会员！',$bUrl,1);
			exit;
		}
		switch ($action){
			case '开通会员':
				$this->_menberOpenUse($OpID,0);
				break;
			case '信用积分开通子账户':
				$this->_menberOpenUse($OpID,0);
				break;
			case '服务中心激活会员':
				$this->_menberOpenUse($OpID,1);
				break;
			case '积分激活会员':
				$this->_menberOpenUse($OpID,2);
				break;
			case '删除会员':
				$this->_menberDelUse($OpID);
				break;
			default:
				$bUrl = __URL__.'/menber';
				$this->_box(0,'没有该会员！',$bUrl,1);
				break;
		}
	}
	
	
	private function _menberOpenUse____y68151制度1($OpID=0,$reg_money=0){
		//=============================================开通会员
		if ($_SESSION['Urlszpass'] == 'MyssShuiPuTao'){
			
// 			$length_arr = count($OpID);
// 			if($length_arr > 1){
// 				$this->error('一次只能开通一个会员');
// 				exit;
// 			}
			
		    $fck = D ('Fck');
			$fee = M ('fee');
			$gouwu = M ('gouwu');
			$shouru = M ('shouru');
//			$blist = M('blist');
			$Guzhi = A('Guzhi');
		    if (!$fck->autoCheckToken($_POST)){
                $this->error('页面过期，请刷新页面！');
                exit;
            }

			//被开通会员参数
			$where = array();
			$where['id'] = array ('in',$OpID);  //被开通会员id数组
			$where['is_pay'] = 0;  //未开通的
			$field = '*';
			$vo = $fck ->where($where)->field($field)->order('id asc')->select();//要开通的会员

			$fee_rs = $fee->field('s2,s3,s13,s9,str20')->find();
			$s2 = explode("|",$fee_rs['s2']);//级别单数
	    	$s3 = explode("|",$fee_rs['s3']);//配送股票积分的比例
			$s9 = $fee_rs['s9'];//投资金额

			//报单中心参数
			$where_two =array();
			$field_two = '*';
			$ID = $_SESSION[C('USER_AUTH_KEY')];
			$where_two['id'] = $ID;
			$where_two['is_agent'] = array('gt',1);//服务中心
			
			$nowdate = strtotime(date('c'));
			$nowday = strtotime(date('Y-m-d'));
			$nowmonth = date('m');
			$fck->emptyTime();
	
			foreach($vo as $voo) {
				$aa = "u_level" . $voo['id'];
				$ulevel = $_POST[$aa];//获取传过来的会员级别
				$f4 = $voo['f4'];
				if ($reg_money == 2) {
//					先看系统是否允许使用积分开通：字段str20
					$str20 = (int)$fee_rs['str20'];
					if (!$str20) {
						$this->error('系统暂不支行使用积分激活！');
						exit;
					}
					$krs = $fck->where('id in(0' . $voo['re_path'] . '0)')->field($field_two)->select();
					foreach ($krs as $woo) {
						$kid = $woo['id'];
						if ($ID == $kid) {
							$frs = $fck->where('id=' . $ID)->find();
							if (!$frs) {
								$this->error('不是自己团队的会员不能开通会员！');
								exit;
							}
						}

					}
				}
				//exit;
				$ppath = $voo['p_path'];
				//上级未开通不能开通下级员工
				$frs_where['is_pay'] = array('eq', 0);
				$frs_where['id'] = $voo['father_id'];
				$frs = $fck->where($frs_where)->find();
				if ($frs) {
					$this->error('开通失败，上级未开通');
					exit;
				}

				if ($reg_money == 2) {
					$aa = $fck->where('id=' . $ID)->find();
					$agent_cash = $aa['agent_cash'];
					if ($agent_cash < $voo['cpzj']) {
						$this->error('积分不够！');
					}
					$result1 = $fck->execute("update __TABLE__ set `agent_cash`=agent_cash-" . $voo['cpzj'] . " where `id`=" . $ID);
					unset($aa);
				}
//				echo "---fffffffffffffffff----";
				if ($result1) {
					//echo "---4444----";
					if ($reg_money == 2) {
						$kt_cont = "推荐人开通会员";
					}

					if ($reg_money == 2) {
						$fck->addencAdd($ID, $voo['user_id'], -$voo['cpzj'], 25, 0, 0, 0, $kt_cont);//历史记录
					}

					//给推荐人添加推荐人数或单数
					$fck->query("update __TABLE__ set `re_nums`=re_nums+1,re_f4=re_f4+1 where `id`=" . $voo['re_id']);

					$nnrs = $fck->where('is_pay>0')->field('n_pai')->order('n_pai desc')->find();
					$mynpai = ((int)$nnrs['n_pai']) + 1;

// 					//接点人信息  开通以后就是小公排
					$arry = array();
					$arry = $this->gongpaixtsmall($voo['re_id']);
					$father_id = $arry['father_id'];
					$father_name = $arry['father_name'];
					$TreePlace = $arry['treeplace'];
					$p_level = $arry['p_level'];
					$p_path = $arry['p_path'];
					$u_pai = $arry['u_pai'];

					$in_gp = $s9[$ulevel - 1] / 2;//配股的金额
					//$in_gp = $s3[0]*$voo['cpzj']/100;
					$data = array();
					$data['is_pay'] = 1;
					$data['pdt'] = mktime();
					$data['u_level'] = $ulevel;
					$data['cpzj'] = $s9[$ulevel - 1];
					$data['f4'] = $f4;
					$data['open'] = 0;
					$data['get_date'] = $nowday;
					$data['fanli_time'] = $nowday - 1;//当天没有分红奖
					$data['agent_lock'] = $in_gp;//
					$data['agent_gp'] = $in_gp;//
					$data['gp_num'] = $in_gp;//
					$data['n_pai'] = $mynpai;
					$data['is_zy'] = $voo['id'];

					//  开通以后就是小公排
					$data['father_id'] = $father_id;
					$data['father_name'] = $father_name;
					$data['treeplace'] = $TreePlace;
					$data['p_level'] = $p_level;
					$data['p_path'] = $p_path;
					$data['u_pai'] = $u_pai;

					//开通会员
					$result = $fck->where('id=' . $voo['id'])->save($data);
					//echo $fck->getLastSql();

					$data1 = array();
					$data1['uid'] = $voo['id'];
					$data1['user_id'] = $voo['user_id'];
					$data1['in_money'] = $s9 * $f4;
					$data1['in_time'] = time();
					$data1['in_bz'] = "新会员加入";
					$shouru->add($data1);

					//统计单数
					// $fck->xiangJiao($voo['id'], $f4);

					//算出奖金
					// $fck->getusjj($voo['id'], 1, $s9 * $f4, $f4);

					$this->_OpenFormyself($voo['id'], $f4 - 1);
				}
			}
//				//全部奖金结算
//				$this->_clearing();

			}
			//exit;
			if ($vo){
				//print_r($vo);
			    //exit;
				$this->messageSMS($voo['id'],1);
				$bUrl = __URL__.'/menber';
				$this->_box(1,'激活会员成功！',$bUrl,2);
				exit;
			}else{
				$bUrl = __URL__.'/menber';
				$this->_box(0,'激活会员失败！',$bUrl,1);
				exit;
			}
		unset($fck,$where,$where_two,$rs,$data,$varray,$vo,$data1);
	}


    private function _menberOpenUse($PTid=0,$reg_money=0){
        //=============================================开通会员
        if ($_SESSION['Urlszpass'] == 'MyssShuiPuTao'){
// 			$length_arr = count($PTid);
// 			if($length_arr > 1){
// 				$this->error('一次只能开通一个会员');
// 				exit;
// 			}
            $ID = $_SESSION[C('USER_AUTH_KEY')];

            $fck = D ('Fck');
            $shouru = M ('shouru');
            $blist = M('blist');
            $fee = M('fee');
            $Guzhi = A('Guzhi');
            $fee_rs = $fee->field('s2,s4')->find();
            $s4 = explode("|",$fee_rs['s4']);
            $s2 = explode("|",$fee_rs['s2']);

            $where = array();
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = 0;
            $field = "*";
            $vo = $fck ->where($where)->field($field)->order('id asc')->select();
            $nowdate = strtotime(date('c'));
            $nowday = strtotime(date('Y-m-d'));

            $fck->emptyTime();

            foreach($vo as $voo){
                $ppath = $voo['p_path'];
                //上级未开通不能开通下级员工
                $frs_where['is_pay'] = array('eq',0);
                $frs_where['id'] = $voo['father_id'];
                $frs = $fck -> where($frs_where) -> find();
                if($frs){
//					$this->error('开通失败，上级未开通');
//					exit;
                }

                $center = $fck->where("id={$ID} and is_agent=2 and is_pay>0")->field('agent_cash,user_id,id')->find();  //找出登录会员(必须为报单中心并且已经登录)
                if ( !$center){
                    $this->error('该代理中心信息有误，请确认是否存在！');
                }

                if ($center['agent_cash'] < $voo['cpzj']){
                    $bUrl = __URL__.'/menber';
                    $this->_box(0,'积分余额不足！',$bUrl,1);
                    exit;
                }
                $result_money =  $this->zijin_log($center['id'],$center['user_id'],"openCenterUser","积分开通会员{$voo['user_id']}",-$voo['cpzj'],"agent_cash");

                if ( !$result_money){
                    $this->error('数据操作失败！');
                }

                //给推荐人添加推荐人数或单数
                $fck->query("update __TABLE__ set `re_nums`=re_nums+1,re_f4=re_f4+".$voo['f4']." where `id`=".$voo['re_id']);

                $nnrs = $fck->where('is_pay>0')->field('n_pai')->order('n_pai desc')->find();
                $mynpai = ((int)$nnrs['n_pai'])+1;


                $in_gp = $s4[$voo['u_level']-1];
                $data = array();
                $data['is_pay'] = 1;
                $data['pdt'] = $nowdate;
                $data['open'] = 1;
                $data['get_date'] = $nowday;
                $data['fanli_time'] = $nowday;//当天没有分红奖
                $data['agent_lock'] = $in_gp;//
                $data['gp_num'] = $in_gp;//
                $data['n_pai'] = $mynpai;
                $data['is_zy']  = $voo['id'];


                $data['pay_time']  = strtotime(date('Y-m-d'));  //当天不发放静态奖

                $point = $this->gongpaixtsmall($voo['re_id']);
                $data['father_id'] = $point['father_id'];
                $data['father_name'] = $point['father_name'];
                $data['treeplace'] = $point['treeplace'];
                $data['p_level'] = $point['p_level'];
                $data['p_path'] = $point['p_path'];
                $data['u_pai'] = $point['u_pai'];

                //开通会员
                $result = $fck->where('id='.$voo['id'])->save($data);
                unset($data,$varray);

                $data = array();
                $data['uid'] = $voo['id'];
                $data['user_id'] = $voo['user_id'];
                $data['in_money'] = $voo['cpzj'];
                $data['in_time'] = time();
                $data['in_bz'] = "新会员加入";
                $shouru->add($data);
                unset($data);


                //统计单数
                // $fck->xiangJiao($voo['id'], $voo['f4']);
                //算出奖金
                // $fck->getusjj($voo['id']);
                //添加报单产品
                // $this->baodanProduct($voo['id'],1);

            }

            unset($fck,$where,$where_two,$rs);
            if ($vo){
                unset($vo);
                $bUrl = __URL__.'/menber';
                $this->_box(1,'开通会员成功！',$bUrl,2);
                exit;
            }else{
                unset($vo);
                $bUrl = __URL__.'/menber';
                $this->_box(0,'开通会员失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }





	//找出最后一个子账号
	public function last_x_num($id){
		$fck=M('fck');
		$count=$fck->where('x_num='.$id)->count();
		if($count){
			return $fck->where('x_num='.$id)->field('id,user_id,re_path,re_name,re_id,re_level,get_ceng')->order('get_ceng desc')->find();
		}else{
			return $fck->where('id='.$id)->field('id,user_id,re_path,re_name,re_id,re_level,get_ceng')->find();
		}
	}
//	开通子帐号
	public function _OpenFormyself($id,$dan){
		if($dan<1) return;
		$fck = D ('Fck');

		$myrs=$fck->where('id='.$id)->find();
		$uLevel =$dan;

		$fee = M('fee');
		$fee_rs = $fee->field('s12,s9,i5')->find();

		$s12 = $fee_rs['s12'];//互助奖
		$s9 =$fee_rs['s9'];
		$nowdate = strtotime(date('c'));
		$nowday=strtotime(date('Y-m-d'));
		//会员级别
		$count=$dan;
		for($i=0;$i<$count;$i++) {
			$data = array();
			//推荐人 start
			$re_info=$this->last_x_num($id);
			$data['re_path'] = $re_info['re_path'].$re_info['id'].',';  //推薦路徑
			$data['re_id'] = $re_info['id'];                              //推薦人ID
			$data['re_name'] = $re_info['user_id'];                       //推薦人帳號
			$data['re_level'] = $re_info['re_level'] + 1;                 //代數(絕對層數)
			$data['get_ceng'] = $re_info['get_ceng'] + 1;                 //代數(絕對層數)
			//推荐人start
			$fck->execute('update __TABLE__ set re_nums=re_nums+1,re_f4=re_f4+1 where id='.$re_info['id']);
			//推荐人 end

			$data['user_id'] = $myrs['user_id'].(string)($re_info['get_ceng'] + 1);
			$data['bind_account'] = '3333';
			$data['last_login_ip'] = '';                            //最後登錄IP
			$data['verify'] = '0';
			$data['status'] = 1;                             //狀態(?)
			$data['type_id'] = '0';
			$data['last_login_time'] = time();                        //最後登錄時間
			$data['login_count'] = 0;                             //登錄次數
			$data['info'] = '信息';
			$data['name'] = '名稱';
			$data['password'] = $myrs['password'];
			$data['passopen'] = $myrs['passopen'];
			$data['pwd1'] = $myrs['pwd1'];
			$data['pwd2'] = $myrs['pwd2'];

			$data['wenti'] = $myrs['wenti'];
			$data['wenti_dan'] = $myrs['wenti_dan'];

			$data['bank_name'] = $myrs['bank_name'];
			$data['bank_card'] = $myrs['bank_card'];
			$data['user_name'] = $myrs['user_name'];
			$data['nickname'] = $myrs['nickname'];
			$data['bank_province'] = $myrs['bank_province'];
			$data['bank_city'] = $myrs['bank_city'];
			$data['bank_address'] = $myrs['bank_address'];
			//$data['user_post']           = $myrs['user_post'];		   //
			$data['user_code'] = $myrs['user_code'];
			$data['user_address'] = $myrs['user_address'];
			$data['email'] = $myrs['email'];
			$data['qq'] = $myrs['qq'];
			$data['user_tel'] = $myrs['user_tel'];
			$data['rdt'] = time();
			$data['u_level'] = $uLevel + 1;
			$data['y_level'] = $myrs['y_level'];
			$data['cpzj'] = $s9;
			$data['f4'] = 1;
			$data['wlf'] = 0;

			$data['is_pay'] = 1;
			$data['rdt'] = time();
			$data['pdt'] = time();
			$data['open'] = 0;
			$data['get_date'] = $nowday;
			$data['fanli_time'] = $nowday;

			$data['x_num'] = $myrs['id'];

			//  开通以后就是小公排
			$data['father_id'] = 1;
			$data['father_name'] = 1;
			$data['treeplace'] = 1;
			$data['p_level'] = 1;
			$data['p_path'] =1;
			$data['u_pai'] = 1;

			$resss = $fck->add($data);
			echo $fck->getDbError();
            unset($data);
		}
		unset($fck,$where);
	}
	//===============================================开通会员
	private function _menberDelUse($OpID=0){
		//=========================================删除会员
		if ($_SESSION['Urlszpass'] == 'MyssShuiPuTao'){
			$fck = M ('fck');
			$where['is_pay'] = 0;
			foreach($OpID as $voo){
				$rs = $fck -> find($voo);
				if($rs){
					$whe['father_name'] = $rs['user_id'];
					$rss = $fck -> where($whe)->field('id') -> find();
					if($rss){
						$bUrl = __URL__.'/menber';
						$this -> error('该 '. $rs['user_id'] .' 会员有下级会员，不能删除！');
						exit;
					}else{
						$where['id'] = $voo;
						$fck -> where($where) -> delete();
					}
				}else{
					$this->error('错误!');
				}
			}
			$bUrl = __URL__.'/menber';
			$this->_box(1,'删除会员！',$bUrl,1);
			exit;
		}else{
			$this->error('错误!');
		}
	}
	
	//已开通会员
	public function frontMenber($Urlsz=0){
		//列表过滤器，生成查询Map对象
		if ($_SESSION['Urlszpass'] == 'MyssDaShuiPuTao'){
			$fck = M('fck');
			$id = $_SESSION[C('USER_AUTH_KEY')];
			$map = array();
			$map['open'] = $id;
			$map['is_pay'] = array('gt',0);
			$UserID = $_POST['UserID'];
			if (!empty($UserID)){
				import ( "@.ORG.KuoZhan" );  //导入扩展类
				$KuoZhan = new KuoZhan();
				if ($KuoZhan->is_utf8($UserID) == false){
					$UserID = iconv('GB2312','UTF-8',$UserID);
				}
				unset($KuoZhan);
				$where['nickname'] = array('like',"%".$UserID."%");
				$where['user_id'] = array('like',"%".$UserID."%");
				$where['_logic']    = 'or';
				$map['_complex']    = $where;
				$UserID = urlencode($UserID);
			}
	
			//查询字段
			$field  = "*";
			//=====================分页开始==============================================
			import ( "@.ORG.ZQPage" );  //导入分页类
			$count = $fck->where($map)->count();//总页数
			$listrows = C('ONE_PAGE_RE');//每页显示的记录数
			$page_where = 'UserID='.$UserID;//分页条件
			$Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
			//===============(总页数,每页显示记录数,css样式 0-9)
			$show = $Page->show();//分页变量
			$this->assign('page',$show);//分页变量输出到模板
			$list = $fck->where($map)->field($field)->order('pdt desc')->page($Page->getPage().','.$listrows)->select();
	
			$HYJJ = '';
			$this->_levelConfirm($HYJJ,1);
			$this->assign('voo',$HYJJ);//会员级别
			$this->assign('list',$list);//数据输出到模板
			//=================================================
	
			$this->display ('frontMenber');
			exit;
		}else{
			$this->error('数据错误2!');
			exit;
		}
	}
	
	
	public function adminAgents(){
		//=====================================后台报单中心管理
		$this->_Admin_checkUser();
		if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGua'){
			$fck = M('fck');
			$UserID = $_POST['UserID'];
			if (!empty($UserID)){
				import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
				$where['nickname'] = array('like',"%".$UserID."%");
				$where['user_id'] = array('like',"%".$UserID."%");
				$where['_logic']    = 'or';
				$map['_complex']    = $where;
				$UserID = urlencode($UserID);
			}
			//$map['is_del'] = array('eq',0);
			$map['is_agent'] = array('gt',0);
			if (method_exists ( $this, '_filter' )) {
				$this->_filter ( $map );
			}
            $field  = '*';
            //=====================分页开始=============================================================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
       		$listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = 'UserID=' . $UserID;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();
            //******************************************************
            $today_start=strtotime(date('Y-m-d'));
            $today_end=$today_start+24*60*60;
            //月初 月末 字符串
            $month_start=date('Y-m-01', strtotime(date("Y-m-d")));
            $month_end=date('Y-m-d', strtotime("$month_start +1 month -1 day"));
            //月初 月末 时间戳
            $month_start=strtotime($month_start);
            $month_end=strtotime($month_end)+24*60*60-1;
//           echo  date('Y-m-d H:i:s',$month_start).'<br>';
//           echo  date('Y-m-d H:i:s',$month_end).'<br>';
            foreach ($list as &$item){
                $item_id=$item['id'];
                //今天的业绩
                $where_today="re_path like '%,{$item_id},%' and (pdt between {$today_start} and {$today_end}) and (pdt > {$item['adt']})";
                $us_bottom=$fck->where($where_today)->select();
                $f4_today=0;
                foreach ($us_bottom as $us){
                    $f4_today+=$us['f4'];
                }
                $item['f4_today']=$f4_today;

//                //这个月的业绩
//                $where_month="re_path like '%,{$item_id},%' and pdt between {$month_start} and {$month_end}";
//                $us_bottom=$fck->where($where_month)->select();
//                $f4_month=0;
//                foreach ($us_bottom as $us){
//                    $f4_month+=$us['f4'];
//                }
//                $item['f4_month']=$f4_month;
            }
            //******************************************************
            $this->assign('list',$list);//数据输出到模板
            //==========================================================================================================

            $Agent_Us_Name = C('Agent_Us_Name');
			$Aname = explode("|",$Agent_Us_Name);
			$this->assign ( 'Aname', $Aname);
			$this->display ('adminAgents');
			return;
		}else{
			$this->error('数据错误!');
			exit;
		}
	}
	
	public function adminAgentsShow(){
		//查看详细信息
		if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGua'){
			$fck = M('fck');
			$ID = (int) $_GET['Sid'];
			$where = array();
			$where['id'] = $ID;
			$srs = $fck->where($where)->field('user_id,verify')->find();
			$this->assign('srs',$srs);
			unset($fck,$where,$srs);
			$this->display ('adminAgentsShow');
			return;
		}else{
			$this->error('数据错误!');
			exit;
		}
	}
	
	public function adminAgentsAC(){  //审核报单中心(报单中心)申请
		$this->_Admin_checkUser();
		//处理提交按钮
		$action = $_POST['action'];
		//获取复选框的值
		$XGid = $_POST['tabledb'];
		$fck = M ('fck');
//	    if (!$fck->autoCheckToken($_POST)){
//            $this->error('页面过期，请刷新页面！');
//            exit;
//        }
        unset($fck);
		if (!isset($XGid) || empty($XGid)){
			$bUrl = __URL__.'/adminAgents';
			$this->_box(0,'请选择会员！',$bUrl,1);
			exit;
		}
		switch ($action){
			case '确认';
				$this->_adminAgentsConfirm($XGid);
				break;
			case '删除';
				$this->_adminAgentsDel($XGid);
				break;
            case '统计下发';
                $this->_xiafa($XGid);
                break;
		default;
			$bUrl = __URL__.'/adminAgents';
			$this->_box(0,'没有该会员！',$bUrl,1);
			break;
		}
	}

    private function _xiafa($XGid){
        $fck  = D ('Fck');
        $where['id'] = array ('in',$XGid);
        $where['is_agent'] = 2;
        $rs = $fck->where($where)->field('*')->select();

        foreach ($rs as $item){
			$money=$item['agent_kt'];
            $result=$fck->execute('update __TABLE__ SET agent_use=agent_use+agent_kt,agent_kt=0 where id='.$item['id']);
            if($result){
                $fck->addencAdd($item['id'],$item['user_id'],$money,3);
            }
        }
        $this->success('下发成功！');
    }
	private function _adminAgentsConfirm($XGid=0){
		//==========================================确认申请报单中心
		if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGua'){
			$fck  = D ('Fck');
			$where['id'] = array ('in',$XGid);
			$where['is_agent'] = 1;
			$rs = $fck->where($where)->field('*')->select();

			$data = array();
			$history = M ('history');
            $rewhere = array();
//          $nowdate = strtotime(date('c'));
            $nowdate = time();
            $jiesuan = 0;
			foreach($rs as $rss){

				$myreid = $rss['re_id'];
				$shoplx = $rss['shoplx'];

				$data['user_id'] = $rss['user_id'];
				$data['uid'] = $rss['uid'];
				$data['action_type'] = '申请成为报单中心';
				$data['pdt'] = $nowdate;
				$data['epoints'] = $rss['agent_no'];
				$data['bz'] = '申请成为报单中心';
				$data['did'] = 0;
				$data['allp'] = 0;
				$history ->add($data);

				$fck ->query("UPDATE __TABLE__ SET is_agent=2,adt=$nowdate,agent_max=0 where id=".$rss['id']);  //开通
			}
			unset($fck,$where,$rs,$history,$data,$rewhere);
			$bUrl = __URL__.'/adminAgents';
			$this->_box(1,'确认申请！',$bUrl,1);
			exit;
		}else{
			$this->error('错误！');
			exit;
		}
	}
	public function adminAgentsCoirmAC(){
		if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGua'){
			//$this->_checkUser();
			$fck = M ('fck');
			$content  = $_POST['content'];
			$userid =trim($_POST['userid']);
			$where['user_id']=$userid;
			//$rs=$fck->where($where)->find();
			$fck_rs = $fck->where($where)->field('id,is_agent,is_pay,user_id,user_name,agent_max,is_agent')->find();
				
	
			if($fck_rs){
				if($fck_rs['is_pay']  == 0){
					$this->error ('临时代理商不能授权报单中心!');
					exit;
				}
				if($fck_rs['is_agent']  == 1){
					$this->error('上次申请还没通过审核!');
					exit;
				}
				if($fck_rs['is_agent']  == 2){
					$this->error('该代理商已是报单中心!');
					exit;
				}
				if(empty($content)){
					$this->error ('请输入备注!');
					exit;
				}
					
				if($fck_rs['is_agent'] == 0){
					$nowdate = time();
					$result = $fck -> query("update __TABLE__ set verify='".$content."',is_agent=2,idt=$nowdate,adt={$nowdate} where id=".$fck_rs['id']);
				}
	
				$bUrl = __URL__ .'/adminAgents';
				$this->_box(1,'授权成功！',$bUrl,2);
			}else{
				$this->error('会员不存在！');
				exit;
			}
		}else{
			$this->error('错误！');
			exit;
		}
	
	}
	private function _adminAgentsDel($XGid=0){
		//=======================================删除申请报单中心信息
		if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGua'){
			$fck = M ('fck');
			$rewhere = array();
			$where['is_agent'] = array('gt',0);
			$where['id'] = array ('in',$XGid);
			$rs = $fck -> where($where) -> select();
			foreach ($rs as $rss){
				$fck ->query("UPDATE __TABLE__ SET is_agent=0,idt=0,adt=0,new_agent=0,shoplx=0,shop_a='',shop_b='' where id>1 and id = ".$rss['id']);
			}
	
			//			$shop->where($where)->delete();
			unset($fck,$where,$rs,$rewhere);
			$bUrl = __URL__.'/adminAgents';
			$this->_box('操作成功','删除申请！',$bUrl,1);
			exit;
		}else{
			$this->error('错误!');
			exit;
		}
	}
    //双轨小公排
    public function gongpaixtsmall($uid){
        $fck = M ('fck');
        $mouid=$uid;
        $field = 'id,user_id,p_level,p_path,u_pai';
        $where = 'is_pay>0 and (p_path like "%,'.$mouid.',%" or id='.$mouid.')';

        $re_rs = $fck ->where($where)->order('p_level asc,u_pai asc')->field($field)->select();
        $fck_where = array();
        foreach($re_rs as $vo){
            $faid=$vo['id'];
            $fck_where['is_pay']   = array('egt',0);
            $fck_where['father_id']   = $faid;
            $count = $fck->where($fck_where)->count();
            if ( is_numeric($count) == false){
                $count = 0;
            }
            if ($count<2){
                $father_id=$vo['id'];
                $father_name=$vo['user_id'];
                $TreePlace=$count;
                $p_level=$vo['p_level']+1;
                $p_path=$vo['p_path'].$vo['id'].',';
                $u_pai=$vo['u_pai']*2+$TreePlace;

                $arry=array();
                $arry['father_id']=$father_id;
                $arry['father_name']=$father_name;
                $arry['treeplace']=$TreePlace;
                $arry['p_level']=$p_level;
                $arry['p_path']=$p_path;
                $arry['u_pai']=$u_pai;
                return $arry;
                break;
            }
        }
    }

	//报单中心表
	public function financeDaoChu_BD(){
		$this->_Admin_checkUser();
		//导出excel
		set_time_limit(0);
	
		header("Content-Type:   application/vnd.ms-excel");
		header("Content-Disposition:   attachment;   filename=Member-Agent.xls");
		header("Pragma:   no-cache");
		header("Content-Type:text/html; charset=utf-8");
		header("Expires:   0");
	
	
	
		$fck = M ('fck');  //奖金表
	
		$map = array();
		$map['id'] = array('gt',0);
		$map['is_agent'] = array('gt',0);
		$field   = '*';
		$list = $fck->where($map)->field($field)->order('idt asc,adt asc')->select();
	
		$title   =   "报单中心表 导出时间:".date("Y-m-d   H:i:s");
	
		echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
		//   输出标题
		echo   '<tr   bgcolor="#cccccc"><td   colspan="9"   align="center">'   .   $title   .   '</td></tr>';
		//   输出字段名
		echo   '<tr  align=center>';
		echo   "<td>序号</td>";
		echo   "<td>会员编号</td>";
		echo   "<td>姓名</td>";
		echo   "<td>联系电话</td>";
		echo   "<td>申请时间</td>";
		echo   "<td>确认时间</td>";
		echo   "<td>类型</td>";
		echo   "<td>报单中心区域</td>";
		echo   "<td>剩余注册币</td>";
		echo   '</tr>';
		//   输出内容
	
		//		dump($list);exit;
	
		$i = 0;
		foreach($list as $row)   {
			$i++;
			$num = strlen($i);
			if ($num == 1){
				$num = '000'.$i;
			}elseif ($num == 2){
				$num = '00'.$i;
			}elseif ($num == 3){
				$num = '0'.$i;
			}else{
				$num = $i;
			}
			if($row['shoplx']==1){
				$nnn = '报单中心';
			}elseif($row['shoplx']==2){
				$nnn = '县/区代理商';
			}else{
				$nnn = '市级代理商';
			}
	
	
			echo   '<tr align=center>';
			echo   '<td>'   .  chr(28).$num   .   '</td>';
			echo   "<td>"   .   $row['user_id'].  "</td>";
			echo   "<td>"   .   $row['user_name'].  "</td>";
			echo   "<td>"   .   $row['user_tel'].  "</td>";
			echo   "<td>"   .   date("Y-m-d H:i:s",$row['idt']).  "</td>";
			echo   "<td>"   .   date("Y-m-d H:i:s",$row['adt']).  "</td>";
			echo   "<td>"   .   $nnn.  "</td>";
			echo   "<td>"   .   $row['shop_a'].  " / " . $row['shop_b']  .   "</td>";
			echo   "<td>"   .   $row['agent_cash'].  "</td>";
			echo   '</tr>';
		}
		echo   '</table>';
	}
	
}
?>